/***************************************************************************
 *   Copyright (C) 2008 by JBox systems
 *   gabi@shaargiora.co.il
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 ***************************************************************************/

#include <string>
#include <iostream>

#include <boost/filesystem.hpp>

#include "utils.h"
#include "log.h"
#include "version.h"

std::vector<Application> loadApplicationDatabase(const char* path) {
	namespace bf = boost::filesystem;
	std::vector<Application> apps;
	bf::path db(path);

	if (bf::is_directory(path)) {
		bf::directory_iterator itr(path), end_itr;
		while (itr != end_itr) {
			bf::path app = itr->path();
			if (boost::filesystem::is_directory(app)) {
				try {
					Application a(app.string());
					apps.push_back(a);
				} catch (AppException) {
					//do nothing
				}
			}
			++itr;
		}
	}

	std::vector<Version> versions;
	for (unsigned int i=0; i < apps.size(); ++i) {
		versions = apps[i].versions();
		for (unsigned int j=0; j < versions.size(); ++j) {
		}
	}
	return apps;
}

std::string stringFromFile(std::string filename) {
	boost::filesystem::path file(filename);
	std::string line="";

	if (boost::filesystem::exists(file)) {
		std::ifstream in(file.string().c_str());
		getline(in, line, '\n');
		in.close();
	}
	return line;
}
